﻿using System;
using System.Data;
using System.Text;
using System.Collections.Generic;
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using System.Data.Common;

namespace Chenxin.Lib.Business.DAL
{
    /// <summary>
    /// 数据访问类t_Contract_Business_CommissionInfoBak。
    /// </summary>
    public class t_Contract_Business_CommissionInfoBak
    {
        public t_Contract_Business_CommissionInfoBak()
        { }
        #region  成员方法

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public static void Add(Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into t_Contract_Business_CommissionInfoBak(");
            strSql.Append("RecordId,ContractId,VenderId,BuyerId,BusinessType,Point,Memo,MajordomoName,MajordomoId,RegionMangerName,RegionMangerId,MangerName,MangerId,DeparterManagerId,BDeparterManagerName,User,UserId,Depart,DepartId,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime,delCityId,delCityName,delCompanyId,delCompanyName,delDepartmentId,delDepartmentName,delUserId,delUserName,delTime)");

            strSql.Append(" values (");
            strSql.Append("@RecordId,@ContractId,@VenderId,@BuyerId,@BusinessType,@Point,@Memo,@MajordomoName,@MajordomoId,@RegionMangerName,@RegionMangerId,@MangerName,@MangerId,@DeparterManagerId,@BDeparterManagerName,@User,@UserId,@Depart,@DepartId,@CreateCityId,@CreateCityName,@CreateCompanyId,@CreateCompanyName,@CreateDepartmentId,@CreateDepartmentName,@CreateUserId,@CreateUserName,@CreateTime,@delCityId,@delCityName,@delCompanyId,@delCompanyName,@delDepartmentId,@delDepartmentName,@delUserId,@delUserName,@delTime)");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "VenderId", DbType.Guid, model.VenderId);
            db.AddInParameter(dbCommand, "BuyerId", DbType.Guid, model.BuyerId);
            db.AddInParameter(dbCommand, "BusinessType", DbType.AnsiString, model.BusinessType);
            db.AddInParameter(dbCommand, "Point", DbType.Decimal, model.Point);
            db.AddInParameter(dbCommand, "Memo", DbType.AnsiString, model.Memo);
            db.AddInParameter(dbCommand, "MajordomoName", DbType.AnsiString, model.MajordomoName);
            db.AddInParameter(dbCommand, "MajordomoId", DbType.Guid, model.MajordomoId);
            db.AddInParameter(dbCommand, "RegionMangerName", DbType.AnsiString, model.RegionMangerName);
            db.AddInParameter(dbCommand, "RegionMangerId", DbType.Guid, model.RegionMangerId);
            db.AddInParameter(dbCommand, "MangerName", DbType.AnsiString, model.MangerName);
            db.AddInParameter(dbCommand, "MangerId", DbType.Guid, model.MangerId);
            db.AddInParameter(dbCommand, "DeparterManagerId", DbType.Guid, model.DeparterManagerId);
            db.AddInParameter(dbCommand, "BDeparterManagerName", DbType.AnsiString, model.BDeparterManagerName);
            db.AddInParameter(dbCommand, "User", DbType.AnsiString, model.User);
            db.AddInParameter(dbCommand, "UserId", DbType.Guid, model.UserId);
            db.AddInParameter(dbCommand, "Depart", DbType.AnsiString, model.Depart);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "CreateCityId", DbType.Guid, model.CreateCityId);
            db.AddInParameter(dbCommand, "CreateCityName", DbType.AnsiString, model.CreateCityName);
            db.AddInParameter(dbCommand, "CreateCompanyId", DbType.Guid, model.CreateCompanyId);
            db.AddInParameter(dbCommand, "CreateCompanyName", DbType.AnsiString, model.CreateCompanyName);
            db.AddInParameter(dbCommand, "CreateDepartmentId", DbType.Guid, model.CreateDepartmentId);
            db.AddInParameter(dbCommand, "CreateDepartmentName", DbType.AnsiString, model.CreateDepartmentName);
            db.AddInParameter(dbCommand, "CreateUserId", DbType.Guid, model.CreateUserId);
            db.AddInParameter(dbCommand, "CreateUserName", DbType.AnsiString, model.CreateUserName);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);
            db.AddInParameter(dbCommand, "delCityId", DbType.Guid, model.delCityId);
            db.AddInParameter(dbCommand, "delCityName", DbType.AnsiString, model.delCityName);
            db.AddInParameter(dbCommand, "delCompanyId", DbType.Guid, model.delCompanyId);
            db.AddInParameter(dbCommand, "delCompanyName", DbType.AnsiString, model.delCompanyName);
            db.AddInParameter(dbCommand, "delDepartmentId", DbType.Guid, model.delDepartmentId);
            db.AddInParameter(dbCommand, "delDepartmentName", DbType.AnsiString, model.delDepartmentName);
            db.AddInParameter(dbCommand, "delUserId", DbType.Guid, model.delUserId);
            db.AddInParameter(dbCommand, "delUserName", DbType.AnsiString, model.delUserName);
            db.AddInParameter(dbCommand, "delTime", DbType.DateTime, model.delTime);
            db.ExecuteNonQuery(dbCommand);
        }
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public static void Update(Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak model)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("update t_Contract_Business_CommissionInfoBak set ");
            strSql.Append("ContractId=@ContractId,");
            strSql.Append("VenderId=@VenderId,");
            strSql.Append("BuyerId=@BuyerId,");
            strSql.Append("BusinessType=@BusinessType,");
            strSql.Append("Point=@Point,");
            strSql.Append("Memo=@Memo,");
            strSql.Append("MajordomoName=@MajordomoName,");
            strSql.Append("MajordomoId=@MajordomoId,");
            strSql.Append("RegionMangerName=@RegionMangerName,");
            strSql.Append("RegionMangerId=@RegionMangerId,");
            strSql.Append("MangerName=@MangerName,");
            strSql.Append("MangerId=@MangerId,");
            strSql.Append("DeparterManagerId=@DeparterManagerId,");
            strSql.Append("BDeparterManagerName=@BDeparterManagerName,");
            strSql.Append("User=@User,");
            strSql.Append("UserId=@UserId,");
            strSql.Append("Depart=@Depart,");
            strSql.Append("DepartId=@DepartId,");
            strSql.Append("CreateCityId=@CreateCityId,");
            strSql.Append("CreateCityName=@CreateCityName,");
            strSql.Append("CreateCompanyId=@CreateCompanyId,");
            strSql.Append("CreateCompanyName=@CreateCompanyName,");
            strSql.Append("CreateDepartmentId=@CreateDepartmentId,");
            strSql.Append("CreateDepartmentName=@CreateDepartmentName,");
            strSql.Append("CreateUserId=@CreateUserId,");
            strSql.Append("CreateUserName=@CreateUserName,");
            strSql.Append("CreateTime=@CreateTime,");
            strSql.Append("delCityId=@delCityId,");
            strSql.Append("delCityName=@delCityName,");
            strSql.Append("delCompanyId=@delCompanyId,");
            strSql.Append("delCompanyName=@delCompanyName,");
            strSql.Append("delDepartmentId=@delDepartmentId,");
            strSql.Append("delDepartmentName=@delDepartmentName,");
            strSql.Append("delUserId=@delUserId,");
            strSql.Append("delUserName=@delUserName,");
            strSql.Append("delTime=@delTime");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, model.RecordId);
            db.AddInParameter(dbCommand, "ContractId", DbType.Guid, model.ContractId);
            db.AddInParameter(dbCommand, "VenderId", DbType.Guid, model.VenderId);
            db.AddInParameter(dbCommand, "BuyerId", DbType.Guid, model.BuyerId);
            db.AddInParameter(dbCommand, "BusinessType", DbType.AnsiString, model.BusinessType);
            db.AddInParameter(dbCommand, "Point", DbType.Decimal, model.Point);
            db.AddInParameter(dbCommand, "Memo", DbType.AnsiString, model.Memo);
            db.AddInParameter(dbCommand, "MajordomoName", DbType.AnsiString, model.MajordomoName);
            db.AddInParameter(dbCommand, "MajordomoId", DbType.Guid, model.MajordomoId);
            db.AddInParameter(dbCommand, "RegionMangerName", DbType.AnsiString, model.RegionMangerName);
            db.AddInParameter(dbCommand, "RegionMangerId", DbType.Guid, model.RegionMangerId);
            db.AddInParameter(dbCommand, "MangerName", DbType.AnsiString, model.MangerName);
            db.AddInParameter(dbCommand, "MangerId", DbType.Guid, model.MangerId);
            db.AddInParameter(dbCommand, "DeparterManagerId", DbType.Guid, model.DeparterManagerId);
            db.AddInParameter(dbCommand, "BDeparterManagerName", DbType.AnsiString, model.BDeparterManagerName);
            db.AddInParameter(dbCommand, "User", DbType.AnsiString, model.User);
            db.AddInParameter(dbCommand, "UserId", DbType.Guid, model.UserId);
            db.AddInParameter(dbCommand, "Depart", DbType.AnsiString, model.Depart);
            db.AddInParameter(dbCommand, "DepartId", DbType.Guid, model.DepartId);
            db.AddInParameter(dbCommand, "CreateCityId", DbType.Guid, model.CreateCityId);
            db.AddInParameter(dbCommand, "CreateCityName", DbType.AnsiString, model.CreateCityName);
            db.AddInParameter(dbCommand, "CreateCompanyId", DbType.Guid, model.CreateCompanyId);
            db.AddInParameter(dbCommand, "CreateCompanyName", DbType.AnsiString, model.CreateCompanyName);
            db.AddInParameter(dbCommand, "CreateDepartmentId", DbType.Guid, model.CreateDepartmentId);
            db.AddInParameter(dbCommand, "CreateDepartmentName", DbType.AnsiString, model.CreateDepartmentName);
            db.AddInParameter(dbCommand, "CreateUserId", DbType.Guid, model.CreateUserId);
            db.AddInParameter(dbCommand, "CreateUserName", DbType.AnsiString, model.CreateUserName);
            db.AddInParameter(dbCommand, "CreateTime", DbType.DateTime, model.CreateTime);
            db.AddInParameter(dbCommand, "delCityId", DbType.Guid, model.delCityId);
            db.AddInParameter(dbCommand, "delCityName", DbType.AnsiString, model.delCityName);
            db.AddInParameter(dbCommand, "delCompanyId", DbType.Guid, model.delCompanyId);
            db.AddInParameter(dbCommand, "delCompanyName", DbType.AnsiString, model.delCompanyName);
            db.AddInParameter(dbCommand, "delDepartmentId", DbType.Guid, model.delDepartmentId);
            db.AddInParameter(dbCommand, "delDepartmentName", DbType.AnsiString, model.delDepartmentName);
            db.AddInParameter(dbCommand, "delUserId", DbType.Guid, model.delUserId);
            db.AddInParameter(dbCommand, "delUserName", DbType.AnsiString, model.delUserName);
            db.AddInParameter(dbCommand, "delTime", DbType.DateTime, model.delTime);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public static void Delete(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("delete from t_Contract_Business_CommissionInfoBak ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            db.ExecuteNonQuery(dbCommand);

        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak GetModel(Guid RecordId)
        {

            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,VenderId,BuyerId,BusinessType,Point,Memo,MajordomoName,MajordomoId,RegionMangerName,RegionMangerId,MangerName,MangerId,DeparterManagerId,BDeparterManagerName,User,UserId,Depart,DepartId,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime,delCityId,delCityName,delCompanyId,delCompanyName,delDepartmentId,delDepartmentName,delUserId,delUserName,delTime from t_Contract_Business_CommissionInfoBak ");
            strSql.Append(" where RecordId=@RecordId ");
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString());
            db.AddInParameter(dbCommand, "RecordId", DbType.Guid, RecordId);
            Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak model = null;
            using (IDataReader dataReader = db.ExecuteReader(dbCommand))
            {
                if (dataReader.Read())
                {
                    model = ReaderBind(dataReader);
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return model;
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public static DataSet GetList(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,VenderId,BuyerId,BusinessType,Point,Memo,MajordomoName,MajordomoId,RegionMangerName,RegionMangerId,MangerName,MangerId,DeparterManagerId,BDeparterManagerName,User,UserId,Depart,DepartId,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime,delCityId,delCityName,delCompanyId,delCompanyName,delDepartmentId,delDepartmentName,delUserId,delUserName,delTime ");
            strSql.Append(" FROM t_Contract_Business_CommissionInfoBak ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            return db.ExecuteDataSet(CommandType.Text, strSql.ToString());
        }

        /*
        /// <summary>
        /// 分页获取数据列表
        /// </summary>
        public static DataSet GetList(int PageSize,int PageIndex,string strWhere)
        {
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business");
            DbCommand dbCommand = db.GetStoredProcCommand("UP_GetRecordByPage");
            db.AddInParameter(dbCommand, "tblName", DbType.AnsiString, "t_Contract_Business_CommissionInfoBak");
            db.AddInParameter(dbCommand, "fldName", DbType.AnsiString, "ID");
            db.AddInParameter(dbCommand, "PageSize", DbType.Int32, PageSize);
            db.AddInParameter(dbCommand, "PageIndex", DbType.Int32, PageIndex);
            db.AddInParameter(dbCommand, "IsReCount", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "OrderType", DbType.Boolean, 0);
            db.AddInParameter(dbCommand, "strWhere", DbType.AnsiString, strWhere);
            return db.ExecuteDataSet(dbCommand);
        }*/

        /// <summary>
        /// 获得数据列表（比DataSet效率高，推荐使用）
        /// </summary>
        public static List<Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak> GetListArray(string strWhere)
        {
            StringBuilder strSql = new StringBuilder();
            strSql.Append("select RecordId,ContractId,VenderId,BuyerId,BusinessType,Point,Memo,MajordomoName,MajordomoId,RegionMangerName,RegionMangerId,MangerName,MangerId,DeparterManagerId,BDeparterManagerName,User,UserId,Depart,DepartId,CreateCityId,CreateCityName,CreateCompanyId,CreateCompanyName,CreateDepartmentId,CreateDepartmentName,CreateUserId,CreateUserName,CreateTime,delCityId,delCityName,delCompanyId,delCompanyName,delDepartmentId,delDepartmentName,delUserId,delUserName,delTime ");
            strSql.Append(" FROM t_Contract_Business_CommissionInfoBak ");
            if (strWhere.Trim() != "")
            {
                strSql.Append(" where " + strWhere);
            }
            List<Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak> list = new List<Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak>();
            Database db = DatabaseFactory.CreateDatabase("Chenxin_Business_Search");
            using (IDataReader dataReader = db.ExecuteReader(CommandType.Text, strSql.ToString()))
            {
                while (dataReader.Read())
                {
                    list.Add(ReaderBind(dataReader));
                }
                dataReader.Close();
                dataReader.Dispose();
            }
            return list;
        }


        /// <summary>
        /// 对象实体绑定数据
        /// </summary>
        public static Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak ReaderBind(IDataReader dataReader)
        {
            Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak model = new Chenxin.Lib.Business.Entity.t_Contract_Business_CommissionInfoBak();
            object ojb;
            ojb = dataReader["RecordId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RecordId = new Guid(ojb.ToString());
            }
            ojb = dataReader["ContractId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.ContractId = new Guid(ojb.ToString());
            }
            ojb = dataReader["VenderId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.VenderId = new Guid(ojb.ToString());
            }
            ojb = dataReader["BuyerId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.BuyerId = new Guid(ojb.ToString());
            }
            model.BusinessType = dataReader["BusinessType"].ToString();
            ojb = dataReader["Point"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.Point = (decimal)ojb;
            }
            model.Memo = dataReader["Memo"].ToString();
            model.MajordomoName = dataReader["MajordomoName"].ToString();
            ojb = dataReader["MajordomoId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MajordomoId = new Guid(ojb.ToString());
            }
            model.RegionMangerName = dataReader["RegionMangerName"].ToString();
            ojb = dataReader["RegionMangerId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.RegionMangerId = new Guid(ojb.ToString());
            }
            model.MangerName = dataReader["MangerName"].ToString();
            ojb = dataReader["MangerId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.MangerId = new Guid(ojb.ToString());
            }
            ojb = dataReader["DeparterManagerId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DeparterManagerId = new Guid(ojb.ToString());
            }
            model.BDeparterManagerName = dataReader["BDeparterManagerName"].ToString();
            model.User = dataReader["User"].ToString();
            ojb = dataReader["UserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.UserId = new Guid(ojb.ToString());
            }
            model.Depart = dataReader["Depart"].ToString();
            ojb = dataReader["DepartId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.DepartId = new Guid(ojb.ToString());
            }
            ojb = dataReader["CreateCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateCityId = new Guid(ojb.ToString());
            }
            model.CreateCityName = dataReader["CreateCityName"].ToString();
            ojb = dataReader["CreateCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateCompanyId = new Guid(ojb.ToString());
            }
            model.CreateCompanyName = dataReader["CreateCompanyName"].ToString();
            ojb = dataReader["CreateDepartmentId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateDepartmentId = new Guid(ojb.ToString());
            }
            model.CreateDepartmentName = dataReader["CreateDepartmentName"].ToString();
            ojb = dataReader["CreateUserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateUserId = new Guid(ojb.ToString());
            }
            model.CreateUserName = dataReader["CreateUserName"].ToString();
            ojb = dataReader["CreateTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.CreateTime = (DateTime)ojb;
            }
            ojb = dataReader["delCityId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.delCityId = new Guid(ojb.ToString());
            }
            model.delCityName = dataReader["delCityName"].ToString();
            ojb = dataReader["delCompanyId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.delCompanyId = new Guid(ojb.ToString());
            }
            model.delCompanyName = dataReader["delCompanyName"].ToString();
            ojb = dataReader["delDepartmentId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.delDepartmentId = new Guid(ojb.ToString());
            }
            model.delDepartmentName = dataReader["delDepartmentName"].ToString();
            ojb = dataReader["delUserId"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.delUserId = new Guid(ojb.ToString());
            }
            model.delUserName = dataReader["delUserName"].ToString();
            ojb = dataReader["delTime"];
            if (ojb != null && ojb != DBNull.Value)
            {
                model.delTime = (DateTime)ojb;
            }
            return model;
        }

        #endregion  成员方法
    }
}

